<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
            text-decoration: none;
        }

        body {
            display: flex;
            height: 100vh;
            align-items: center;
            justify-content: center;
            /* background-color: cadetblue; */
        }

        .shell {
            border: 3px solid #fff;
            width: 500px;
            height: 300px;
            position: relative;
            overflow: hidden;
            box-shadow: 20px 30px 20px rgba(0, 0, 0, .5);
        }

        .images {
            width: 300%;
            height: 100%;
            display: flex;
            position: absolute;
            left: 0;
            transition: 0.2s;
            /* left: -200%; */
        }

        .img {
            width: 100%;
            background-size: contain;
            background-repeat: no-repeat;
            background-position: center;
        }

        .img:nth-child(1) {
            background-image: url('../img/java.png');
        }

        .img:nth-child(2) {
            background-image: url('../img/快乐加倍.png');
        }

        .img:nth-child(3) {
            background-image: url('../img/java.png');
        }

        .min-images {
            display: flex;
            justify-content: space-evenly;
            position: absolute;
            bottom: 20px;
            width: 40%;
            z-index: 3;
            right: 10%;

        }

        .min {
            width: 50px;
            height: 50px;
            cursor: pointer;
            border-radius: 50%;
            background-size: contain;
            border: 5px solid rgba(255, 255, 255, 0.5);
            background-position: center;
            /* background-repeat: no-repeat; */

        }

        .min:nth-child(1) {
            background-image: url("../img/java.png");
        }

        .min:nth-child(2) {
            background-image: url("../img/快乐加倍.png");
        }

        .min:nth-child(3) {
            background-image: url("../img/java.png");
        }

        .button {

            width: 100%;
            height: 100%;
            position: absolute;
            /* background-color: red; */
            display: flex;
            justify-content: space-between;
            /* 不允许选文本 */
            user-select: none;


        }

        .button-left,
        .button-right {

            font-style: 50px;
            background-color: rgba(160, 190, 255, 0.7);
            padding: 0 20px;
            line-height: 300px;

        }
    </style>

</head>

<body>
    <div class="shell">
        <ul class="images">
            <li class="img">1</li>
            <li class="img">2</li>
            <li class="img">3</li>
        </ul>
        <ul class="min-images">
            <li class="min"></li>
            <li class="min"></li>
            <li class="min"></li>
        </ul>
        <dov class="button">
            <div class="button-left">《</div>
            <div class="button-right">》</div>
        </dov>
    </div>

    <script>
        let left = document.querySelector(".button-left");
        let right = document.querySelector(".button-right");
        let min = document.querySelectorAll(".min")
        let images = document.querySelector(".images")

        let index = 0;
        let time;
        // debugger

        function position() {
            images.style.left = (index * -100) + '%'

        }
        // position()

        function add() {
            if (index >= min.length - 1) {
                index = 0;
            } else {
                index++;
            }

        }

        function desc() {
            if (index < 1) {
                index = min.length - 1;
            } else {
                index--;
            }

        }

        function timer() {
            time = setInterval(() => {
                // index++
                // desc()
                add()
                position()
                console.log(index);
            }, 3000)
        }
        timer()
        left.addEventListener('click', () => {
            debugger
            desc()
            position()
            clearInterval(time)
            timer()
        });
        right.addEventListener('click', () => {
            debugger
            add()
            position()
            clearInterval(time)
            timer()
        })
        for (let i = 0; i < min.length; i++) {
            min[i].addEventListener('click', () => {
                index = i;
                position();
                clearInterval(time);
                timer();
            })
        }
    </script>
</body>

</html>